<template>
  <div class="app-container">
    <!-- 查询区域 -->
    <el-form :model="queryParams" :ref="queryFormRef" v-show="showSearch" inline label-width="auto" @keyup.enter.native="handleQuery">
        <el-form-item label="关键字" prop="keywords" >
          <el-input v-model="queryParams.keywords" placeholder="请输入关键字" clearable />
        </el-form-item>
        <el-form-item label="路径签名" prop="sign">
          <el-input v-model="queryParams.sign" placeholder="文件路径签名" clearable />
        </el-form-item>
        <el-form-item label="业务类型" prop="busiType">
          <lam-dict-select v-model="queryParams.busiType" dictCode="file_busi_type" placeholder="业务类型" clearable />
        </el-form-item>
        <el-form-item label="类型" prop="fileType">
          <lam-dict-select v-model="queryParams.fileType" dictCode="file_type" placeholder="类型" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <lam-dict-select v-model="queryParams.status" dictCode="file_status" placeholder="状态" clearable />
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="tool-bar-btn">
      <el-button type="success" icon="el-icon-tickets" :disabled="single" @click="handleDetail" v-hasPerms="['sys:file:detail']">详情</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="multiple" @click="handleDelete" v-hasPerms="['sys:file:remove']">删除</el-button>
      <el-button type="warning" icon="el-icon-download" @click="handleExport" v-hasPerms="['sys:file:export']">导出</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </div>

    <selected-info :count="selectedRows.length" :onClearSelected="onClearSelected" />
    <el-table :ref="dataTableRef" v-loading="loading" :data="dataList" stripe border @selection-change="onSelectChange"
          :default-sort = "defaultSort" @sort-change="onSortChange" :row-key="rowKey" >
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="文件路径" header-align="center" prop="filePath" :show-overflow-tooltip="true" width="500" />
      <el-table-column label="路径签名" header-align="center" prop="sign"  width="280" />
      <el-table-column label="文件类型" align="center" prop="fileTypeDictText" width="120"/>
      <el-table-column label="文件大小" align="center" prop="fileSize"  width="150" />
      <el-table-column label="业务类型" align="center" prop="busiTypeDictText" width="120"/>
      <el-table-column label="存储位置" align="center" prop="locationDictText" width="120"/>
      <el-table-column label="使用标识" align="center" prop="useFlagDictText" width="120"/>
      <el-table-column label="状态" align="center" prop="statusDictText" width="80">
        <template slot-scope="{row}">
          <LamStatus :value="row.status" :text="row.statusDictText" :styleMap="statusStyle"/>
        </template>
      </el-table-column>
      <el-table-column label="过期时间" align="center" prop="expireTime" width="180"/>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
        <template slot-scope="{row}">
          <el-button type="text" icon="el-icon-download" @click="download(row)" v-if="row.status==1" v-hasPerms="['sys:file:download']">下载</el-button>
          <el-button type="text" icon="el-icon-tickets" @click="handleDetail(row)" v-hasPerms="['sys:file:detail']">详情</el-button>
          <el-button type="text" icon="el-icon-delete" @click="handleDelete(row)" v-hasPerms="['sys:file:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="!loading" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"  @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <EditFile ref="formDialog" @ok="getList" />

    <!-- 导出对话框 -->
    <ToExport ref="exportDialog" />

    <DownloadIframe ref="downloadIframe" />

  </div>
</template>

<script>
import {httpGet, httpDel} from '@/api';
import { IndexListMixin } from '@/components/mixins/IndexListMixin';
import EditFile from './edit';
import ToExport from '@/components/download/ToExport';
import DownloadIframe from '@/components/download/DownloadIframe';

export default {
  name: "File",
  mixins:[IndexListMixin],
  components: {
    EditFile,
    ToExport,
    DownloadIframe
  },
  data() {
    return {
      statusStyle:{
        '0':'gray',
        '2':'red'
      },
      // 查询参数
      queryParams: {
        sign: null,
        filePathKey: null,
        fileType: null,
        status: null,
        pageNum: 1,
        pageSize: 10
      },
      url: {
      	exportXls: '/sys/file/export',
        base: '/sys/file/',
      	list: '/sys/file/list'
      }
    };
  },
  created() {
    this.getList();
  },
  mounted(){
  },
  methods: {
    getList() {
      this.loadData(this.url.list);
    },

    /** 查看详情按钮操作 */
    handleDetail(row) {
      const id = row.id || this.selectedRowKeys
      this.$refs.formDialog.toDetail("查看文件记录详情", httpGet(this.url.base + id));
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.selectedRowKeys
      this.deleteData(this.url.base, ids);
    },

    /** 导出按钮操作 */
    handleExport() {
      this.exportData('文件记录导出', this.url.exportXls, this.queryParams);
    },

    download(row){
      this.$refs.downloadIframe.download({t: row.fileType, s: row.sign})
    },
  }
};
</script>
